//
//  SSFirstPageTravelHotCityCell.m
//  Travel_World
//
//  Created by dlios on 15/10/14.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "SSFirstPageTravelHotCityCell.h"
#import "SSFirstPageTravelCityModel.h"
#import "SSFirstPageTravelHotCityCellCell.h"
#import "UIImageView+WebCache.h"

@implementation SSFirstPageTravelHotCityCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createHotCityCollectionView];
    }
    
    return self;
}

- (void)createHotCityCollectionView
{
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.hotCityCollectionView = [[UICollectionView alloc] initWithFrame:self.contentView.frame collectionViewLayout:self.flowLayout];
    self.hotCityCollectionView.backgroundColor = [UIColor whiteColor];
    self.hotCityCollectionView.delegate = self;
    self.hotCityCollectionView.dataSource = self;
    [self.hotCityCollectionView registerClass:[SSFirstPageTravelHotCityCellCell class] forCellWithReuseIdentifier:@"city"];
    [self.contentView addSubview:_hotCityCollectionView];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.cityArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SSFirstPageTravelHotCityCellCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"city" forIndexPath:indexPath];
    [cell.cityImageView sd_setImageWithURL:[NSURL URLWithString:[self.cityArr[indexPath.row] photo]] placeholderImage:[UIImage imageNamed:@"placeholder1"]];
    
    cell.cnnameLabel.text = [self.cityArr[indexPath.row] cnname];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.delegate clickHotCityCollectionViewCellByItem:indexPath.row];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.flowLayout.itemSize = CGSizeMake((MINW - 40) / 4, (MINW - 40) / 5);
    self.flowLayout.minimumInteritemSpacing = (MINW - 40) / 17;
    self.flowLayout.minimumLineSpacing = (MINW - 40) / 17;
    self.flowLayout.sectionInset = UIEdgeInsetsMake((MINW - 40) / 16, (MINW - 40) / 16, (MINW - 40) / 16, (MINW - 40) / 16);
    
    self.hotCityCollectionView.frame = self.contentView.frame;
}

- (void)awakeFromNib {
    // Initialization code
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
